<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>提莫攻击</title>
</head>
<body>
  <script>
    var timeSeries = [1, 6]
    var duration = 2
    function fn(timeSeries, duration) {
      let res = 0
      let len = timeSeries.length // len = 2
      for (let i = 1; i < len; i++) {// i = 1
        // a[1] - a[0] = 6 - 1
        let num = timeSeries[i] - timeSeries[i - 1] // sum = 5
        if (num < duration) {
          res += num
        } else {
          res += duration
        }
      }
      return res + duration
    };
    console.log(fn(timeSeries, duration));
  </script>
</body>
</html>